package operation.util;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class StringUtil {
    public static Set<Long> convertIds2Set(String ids) {
        if (StringUtils.isBlank(ids)) {
            return new LinkedHashSet();
        } else {
            Set<Long> idSet = new LinkedHashSet();
            Arrays.stream(StringUtils.split(ids, ",")).filter(StringUtils::isNotEmpty).forEach((item) -> {
                if (StringUtils.isNumeric(item)) {
                    idSet.add(Long.valueOf(item));
                }

            });
            return idSet;
        }
    }

    private StringUtil() {
    }

    /**
     * 去除字符串中的空格、回车、换行符、制表符等
     * @param str
     * @return
     */
    public static String replaceSpecialStr(String str) {
        String repl = "";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            repl = m.replaceAll("");
        }
        return repl;
    }
}
